using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

namespace JGSY.CMS.LowCode.Platform.Application.DTOs.Authentication;

/// <summary>
/// 刷新令牌请求模型
/// </summary>
public class RefreshTokenRequest
{
    /// <summary>
    /// 刷新令牌
    /// </summary>
    /// <example>eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...</example>
    [Required(ErrorMessage = "刷新令牌不能为空")]
    [JsonPropertyName("refreshToken")]
    public string RefreshToken { get; set; } = string.Empty;
}

/// <summary>
/// 刷新令牌响应模型
/// </summary>
public class RefreshTokenResponse
{
    /// <summary>
    /// 是否成功
    /// </summary>
    /// <example>true</example>
    [JsonPropertyName("success")]
    public bool Success { get; set; }

    /// <summary>
    /// 新的访问令牌
    /// </summary>
    /// <example>eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...</example>
    [JsonPropertyName("accessToken")]
    public string? AccessToken { get; set; }

    /// <summary>
    /// 新的刷新令牌
    /// </summary>
    /// <example>eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...</example>
    [JsonPropertyName("refreshToken")]
    public string? RefreshToken { get; set; }

    /// <summary>
    /// 过期时间（秒）
    /// </summary>
    /// <example>3600</example>
    [JsonPropertyName("expiresIn")]
    public int ExpiresIn { get; set; }

    /// <summary>
    /// 错误消息
    /// </summary>
    /// <example>刷新令牌已过期</example>
    [JsonPropertyName("message")]
    public string? Message { get; set; }
}

/// <summary>
/// 短信验证码发送请求
/// </summary>
public class SendSmsRequest
{
    /// <summary>
    /// 手机号码
    /// </summary>
    /// <example>13800138000</example>
    [Required(ErrorMessage = "手机号码不能为空")]
    [RegularExpression(@"^1[3-9]\d{9}$", ErrorMessage = "手机号码格式不正确")]
    [JsonPropertyName("phoneNumber")]
    public string PhoneNumber { get; set; } = string.Empty;

    /// <summary>
    /// 验证码类型
    /// </summary>
    /// <example>login</example>
    [JsonPropertyName("type")]
    public string Type { get; set; } = "login"; // login, register, reset_password
}

/// <summary>
/// 短信验证码验证请求
/// </summary>
public class VerifySmsRequest
{
    /// <summary>
    /// 手机号码
    /// </summary>
    /// <example>13800138000</example>
    [Required(ErrorMessage = "手机号码不能为空")]
    [JsonPropertyName("phoneNumber")]
    public string PhoneNumber { get; set; } = string.Empty;

    /// <summary>
    /// 验证码
    /// </summary>
    /// <example>123456</example>
    [Required(ErrorMessage = "验证码不能为空")]
    [StringLength(6, MinimumLength = 4, ErrorMessage = "验证码长度必须在4-6位之间")]
    [JsonPropertyName("verificationCode")]
    public string VerificationCode { get; set; } = string.Empty;
}

/// <summary>
/// 密码重置请求
/// </summary>
public class PasswordResetRequest
{
    /// <summary>
    /// 邮箱地址
    /// </summary>
    /// <example>user@example.com</example>
    [Required(ErrorMessage = "邮箱地址不能为空")]
    [EmailAddress(ErrorMessage = "邮箱地址格式不正确")]
    [JsonPropertyName("email")]
    public string Email { get; set; } = string.Empty;
}

/// <summary>
/// 密码重置确认请求
/// </summary>
public class PasswordResetConfirmRequest
{
    /// <summary>
    /// 邮箱地址
    /// </summary>
    /// <example>user@example.com</example>
    [Required(ErrorMessage = "邮箱地址不能为空")]
    [EmailAddress(ErrorMessage = "邮箱地址格式不正确")]
    [JsonPropertyName("email")]
    public string Email { get; set; } = string.Empty;

    /// <summary>
    /// 重置码
    /// </summary>
    /// <example>123456</example>
    [Required(ErrorMessage = "重置码不能为空")]
    [JsonPropertyName("resetCode")]
    public string ResetCode { get; set; } = string.Empty;

    /// <summary>
    /// 新密码
    /// </summary>
    /// <example>NewPassword123!</example>
    [Required(ErrorMessage = "新密码不能为空")]
    [StringLength(100, MinimumLength = 6, ErrorMessage = "密码长度必须在6-100个字符之间")]
    [JsonPropertyName("newPassword")]
    public string NewPassword { get; set; } = string.Empty;
}

/// <summary>
/// 通用操作结果
/// </summary>
public class OperationResult
{
    /// <summary>
    /// 是否成功
    /// </summary>
    /// <example>true</example>
    [JsonPropertyName("success")]
    public bool Success { get; set; }

    /// <summary>
    /// 消息
    /// </summary>
    /// <example>操作成功</example>
    [JsonPropertyName("message")]
    public string Message { get; set; } = string.Empty;

    /// <summary>
    /// 错误码
    /// </summary>
    /// <example>null</example>
    [JsonPropertyName("errorCode")]
    public string? ErrorCode { get; set; }
}

/// <summary>
/// 用户信息响应
/// </summary>
public class CurrentUserResponse
{
    /// <summary>
    /// 用户ID
    /// </summary>
    /// <example>1001</example>
    [JsonPropertyName("id")]
    public long Id { get; set; }

    /// <summary>
    /// 用户名
    /// </summary>
    /// <example>admin</example>
    [JsonPropertyName("username")]
    public string Username { get; set; } = string.Empty;

    /// <summary>
    /// 邮箱
    /// </summary>
    /// <example>admin@example.com</example>
    [JsonPropertyName("email")]
    public string Email { get; set; } = string.Empty;

    /// <summary>
    /// 显示名称
    /// </summary>
    /// <example>系统管理员</example>
    [JsonPropertyName("displayName")]
    public string DisplayName { get; set; } = string.Empty;

    /// <summary>
    /// 头像URL
    /// </summary>
    /// <example>/uploads/avatars/admin.jpg</example>
    [JsonPropertyName("avatar")]
    public string? Avatar { get; set; }

    /// <summary>
    /// 角色列表
    /// </summary>
    /// <example>["Admin", "Manager"]</example>
    [JsonPropertyName("roles")]
    public List<string> Roles { get; set; } = new();

    /// <summary>
    /// 权限列表
    /// </summary>
    /// <example>["user:read", "user:write"]</example>
    [JsonPropertyName("permissions")]
    public List<string> Permissions { get; set; } = new();

    /// <summary>
    /// 最后登录时间
    /// </summary>
    /// <example>2025-08-08T10:30:00.000Z</example>
    [JsonPropertyName("lastLoginAt")]
    public DateTime? LastLoginAt { get; set; }
}
